package com.cloud.security.handler;

import com.cloud.enums.SecurityEnum;
import com.cloud.pojo.sys.Result;
import com.cloud.util.SecurityHandlerUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未登录处理逻辑
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
        SecurityHandlerUtil.responseHandler(response, Result.createFail(SecurityEnum.NOT_LOGIN.getCode(), SecurityEnum.NOT_LOGIN.getDesc()));
    }
}
